package com.cskaoyan.service.orderwx;


import com.cskaoyan.mapper.*;
import com.cskaoyan.model.bo.orderwx.CskaoyanmallOrder;
import com.cskaoyan.model.bo.orderwx.CskaoyanmallOrderGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class WxOrderServiceImpl implements WxOrderService {
    @Autowired
    CskaoyanmallOrderMapper orderMapper;

    @Autowired
    CouponMapper couponMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;

    @Autowired
    CskaoyanmallOrderGoodsMapper cskaoyanmallOrderGoodsMapper;


    @Override
    public void deleteOrder(Integer orderId) {
        CskaoyanmallOrder order = new CskaoyanmallOrder();
        order.setId(orderId);
        order.setDeleted(true);
        order.setUpdateTime(new Date());
        orderMapper.updateByPrimaryKeySelective(order);
        orderGoodsMapper.updateOrderGoodsSelective(orderId);
    }

    @Override
    public void cancelOrder(Integer id) {
        CskaoyanmallOrder order = new CskaoyanmallOrder();
        order.setId(id);
        order.setOrderStatus(102);
        order.setUpdateTime(new Date());
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public void refundOrder(Integer id) {
        CskaoyanmallOrder order = new CskaoyanmallOrder();
        order.setId(id);
        order.setEndTime(new Date());
        order.setOrderStatus(203);
        order.setUpdateTime(new Date());
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public void confirmOrder(Integer id) {
        CskaoyanmallOrder order = new CskaoyanmallOrder();
        order.setId(id);
        order.setConfirmTime(new Date());
        order.setOrderStatus(401);
        order.setUpdateTime(new Date());
        order.setConfirmTime(new Date());
        orderMapper.updateByPrimaryKeySelective(order);
    }

//    @Override
//    public CskaoyanmallOrderGoods selectGoods(Integer orderId, Integer goodsId) {
//        CskaoyanmallOrderGoods cskaoyanmallOrderGoods = cskaoyanmallOrderGoodsMapper.selectByOrderIdAndGoodsId(orderId, goodsId);
//        return cskaoyanmallOrderGoods;
//    }

    @Override
    public void prepayGoods(Integer orderId) {
        CskaoyanmallOrder order = new CskaoyanmallOrder();
        order.setId(orderId);
        order.setConfirmTime(new Date());
        order.setOrderStatus(201);
        order.setUpdateTime(new Date());
        order.setConfirmTime(new Date());
        orderMapper.updateByPrimaryKeySelective(order);
    }
}
